<html>
<head>
<link rel="stylesheet" href="../../../js/sh/SyntaxHighlighter.css" type="text/css" />
<script src="../../../js/sh/shCore.js"></script>
<script src="../../../js/sh/shBrushJava.js"></script>
<style>

* {
font-family:Courier New,monospace;
  padding: 0;
  margin: 0;
  white-space: nowrap;
  font-size: 11px;
}

.dp-highlighter {
  white-space: nowrap;
  overflow: visible;
  width: 600px;
  font-size: 11px;
  font-family:Courier New,monospace;
}
</style>

</head>
<body>
<textarea name="code" class="java:nogutter" rows="15" cols="120">
/*
 * SmartGWT (GWT for SmartClient)
 * Copyright 2008 and beyond, Isomorphic Software, Inc.
 *
 * SmartGWT is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation.  SmartGWT is also
 * available under typical commercial license terms - see
 * http://smartclient.com/license
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 */

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.DragDataAction;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;

public class DragMoveSample implements EntryPoint {

    public void onModuleLoad() {

        HLayout hLayout = new HLayout();
        hLayout.setMembersMargin(15);
        hLayout.setLayoutMargin(15);

        ListGrid countryGrid = new ListGrid();
        countryGrid.setWidth(300);
        countryGrid.setHeight(224);
        countryGrid.setAlternateRecordStyles(true);
        countryGrid.setShowAllRecords(true);
        countryGrid.setCanReorderRecords(true);
        countryGrid.setCanDragRecordsOut(true);
        countryGrid.setCanAcceptDroppedRecords(true);
        countryGrid.setDragDataAction(DragDataAction.MOVE);

        ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 50);
        countryCodeField.setAlign(Alignment.CENTER);
        countryCodeField.setType(ListGridFieldType.IMAGE);
        countryCodeField.setImageURLPrefix("flags/16/");
        countryCodeField.setImageURLSuffix(".png");

        ListGridField nameField = new ListGridField("countryName", "Country", 120);
        ListGridField capitalField = new ListGridField("capital", "Capital");

        countryGrid.setFields(new ListGridField[]{countryCodeField, nameField, capitalField});
        countryGrid.setData(getRecords());

        ListGrid countryGrid2 = new ListGrid();
        countryGrid2.setWidth(200);
        countryGrid2.setHeight(224);
        countryGrid2.setAlternateRecordStyles(true);
        countryGrid2.setShowAllRecords(true);
        countryGrid2.setEmptyMessage("Drop Rows Here");
        countryGrid2.setCanReorderFields(true);
        countryGrid2.setCanDragRecordsOut(true);
        countryGrid2.setCanAcceptDroppedRecords(true);
        countryGrid2.setDragDataAction(DragDataAction.MOVE);
        countryGrid2.setFields(new ListGridField[]{countryCodeField, nameField});

        hLayout.addMember(countryGrid);
        hLayout.addMember(countryGrid2);
        hLayout.draw();
    }

    private ListGridRecord[] getRecords() {
        return new CountryRecord[]{
                new CountryRecord("North America", "United States", "US", 9631420, 298444215),
                new CountryRecord("Asia", "China", "CH", 9596960, 1313973713),
                new CountryRecord("Asia", "Japan", "JA", 377835, 127463611),
                new CountryRecord("Asia", "India", "IN", 3287590, 1095351995),
                new CountryRecord("Europe", "Germany", "GM", 357021, 82422299),
                new CountryRecord("Europe", "United Kingdom", "UK", 244820, 60609153),
                new CountryRecord("Europe", "France", "FR", 547030, 60876136),
                new CountryRecord("Europe", "Italy", "IT", 301230, 58133509),
                new CountryRecord("Europe", "Russia", "RS", 17075200, 142893540),
                new CountryRecord("South America", "Brazil", "BR", 8511965, 188078227)
        };
    }

}

class CountryRecord extends ListGridRecord {

    public CountryRecord() {
    }

    public CountryRecord(String continent, String countryName, String countryCode, int area, int population) {

        setContinent(continent);
        setCountryName(countryName);
        setCountryCode(countryCode);
        setArea(area);
        setPopulation(population);
    }

    public void setContinent(String continent) {
        setAttribute("continent", continent);
    }

    public String getContinent() {
        return getAttributeAsString("continent");
    }

    public void setCountryName(String countryName) {
        setAttribute("countryName", countryName);
    }

    public String getCountryName() {
        return getAttributeAsString("countryName");
    }

    public void setCountryCode(String countryCode) {
        setAttribute("countryCode", countryCode);
    }

    public String getCountryCode() {
        return getAttributeAsString("countryCode");
    }

    public void setArea(int area) {
        setAttribute("area", area);
    }

    public int getArea() {
        return getAttributeAsInt("area");
    }

    public void setPopulation(int population) {
        setAttribute("population", population);
    }

    public int getPopulation() {
        return getAttributeAsInt("population");
    }
}
</textarea>
<script class="javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script>
</body>
</html>
